package top.lishuoboy.hibernate.validator.a5;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.SuperBuilder;
import top.lishuoboy.hibernate.validator.a5.validate.group.DeleteGroup;
import top.lishuoboy.hibernate.validator.a5.validate.group.InsertGroup;
import top.lishuoboy.hibernate.validator.a5.validate.group.UpdateGroup;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.validation.groups.Default;

@Data
@NoArgsConstructor
@AllArgsConstructor
@SuperBuilder
@Accessors(chain = true)
//除了定义组序列之外，@GroupSequence注释还允许重新定义给定类的默认组。为此，只需将注释添加到类中，并指定在注释中@GroupSequence替代此类的组的顺序Default
//默认为@GroupSequence({})或@GroupSequence({User.class})。【注意】新定义的序列value不能包含Default.class且当value有值时必须包含User.class
//@GroupSequence({InsertGroup.class, User.class})

// 重新定义默认组序列-动态
//@GroupSequenceProvider(UserGroupSequenceProvider.class)
public class User {
    // 不指定分组，默认为Default.class
    @NotNull(groups = {DeleteGroup.class, UpdateGroup.class})
    private Integer id;

    // 不指定分组，默认为Default.class
    @NotBlank(groups = {InsertGroup.class})
    @Size(min = 2, max = 60, groups = {Default.class})
    private String name;

    // 不指定分组，默认为Default.class
    @Email(groups = {Default.class})
//    @ConvertGroup(from = Default.class, to = InsertGroup.class)  // 组转换
    private String email;

}